var $editForm = $("#editForm");
$editForm.delegate('.js-submit', 'click', function() {
    $editForm.data('bootstrapValidator').validate();
    if (!$editForm.data('bootstrapValidator').isValid()) {
        return false;
    }
    if (!confirm("确定要提交修改？")) {
        return false;
    }

    var url = $editForm.attr('action');
    var param = serializeArrayToJson($editForm.serializeArray());
    $.post(url, param, function(resp) {
        if (resp.code != 0) {
            doAlert(resp.message || '操作失败！');
            return false;
        }
        var id = resp.data ? (resp.data.id || '') : '';
        doAlert('修改成功！', 1500, 'success', function() {
            var callback = $editForm.attr('data-list-url') || '';
            callback = callback.replace('[id]', id);
            window.location.href = callback || "./list"
        })
    })
})
function initValidator() {
    $editForm.bootstrapValidator({
        container: 'tooltip',
        excluded: [":disabled"],
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        }
    });
}

$(document).ready(function() {
    initValidator();
})